package com.itkjb.leisurely.resource.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itkjb.leisurely.core.base.service.impl.BaseServiceImpl;
import com.itkjb.leisurely.resource.sys.mapper.SysUserInfoMapper;
import com.itkjb.leisurely.resource.sys.model.SysUserInfoModel;
import com.itkjb.leisurely.resource.sys.service.ISysUserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户详情 服务实现类
 * </p>
 *
 * @author itkjb.com
 * @since 2020-07-17
 */
@Service
public class SysUserInfoServiceImpl extends BaseServiceImpl<SysUserInfoMapper, SysUserInfoModel> implements ISysUserInfoService {

    /**
     * wrapper 组装器，构造条件查询
     * @author itkjb.com
     * @date  2020-07-17
     * @param wrapper
     * @param model 条件
     **/
    @Override
    protected void assembleWrapper(QueryWrapper<SysUserInfoModel> wrapper, SysUserInfoModel model) {
        // （代码生成器生成）自动生成了，list查询的时候，条件组装，开发者自行删除不需要的条件
        // 姓名
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getName()), SysUserInfoModel::getName, model.getName() );
        // 身份证号
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getIdCardNo()), SysUserInfoModel::getIdCardNo, model.getIdCardNo() );
        // 护照号
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getPassportNo()), SysUserInfoModel::getPassportNo, model.getPassportNo() );
        // 联系电话
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getLinkPhone()), SysUserInfoModel::getLinkPhone, model.getLinkPhone() );
        // 1：男 2：女 0：不详
        wrapper.lambda().eq(model.getSex() != null, SysUserInfoModel::getSex, model.getSex() );
        // 省id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getProvinceId()), SysUserInfoModel::getProvinceId, model.getProvinceId() );
        // 市id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getCityId()), SysUserInfoModel::getCityId, model.getCityId() );
        // 县id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getCountyId()), SysUserInfoModel::getCountyId, model.getCountyId() );
        // 县级以上名字，中间用-分割
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getCountyName()), SysUserInfoModel::getCountyName, model.getCountyName() );
        // 详细地址
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getAddress()), SysUserInfoModel::getAddress, model.getAddress() );
        // qq号
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getQqNo()), SysUserInfoModel::getQqNo, model.getQqNo() );
        // 微信号
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getWeixiNo()), SysUserInfoModel::getWeixiNo, model.getWeixiNo() );
        // 头像
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getAvatar()), SysUserInfoModel::getAvatar, model.getAvatar() );
        // 备注
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getRemark()), SysUserInfoModel::getRemark, model.getRemark() );
    }

    /**
     * wrapper 组装器，组装list查询时，查询的列
     * @author itkjb.com
     * @date  2020-07-17
     * @param wrapper
     * @param model
     * @return void
     * @since 2020-07-17
     **/
    @Override
    protected void buildListSelectColumns(QueryWrapper<SysUserInfoModel> wrapper, SysUserInfoModel model){
        buildCommonSelectColumns(wrapper, model);
    }

    /**
     * 组装列表查询的列（字段）
     * @date  2020-07-17
     * @param wrapper
     * @param model
     */
    protected void buildCommonSelectColumns(QueryWrapper<SysUserInfoModel> wrapper, SysUserInfoModel model){
        // 代码生成器生成，为了简化开发时，查询list时，查询指定字段，没必要查询所有参数
        wrapper.lambda().select(
            // 用户关联id
            SysUserInfoModel::getId,
            // 姓名
            SysUserInfoModel::getName,
            // 身份证号
            SysUserInfoModel::getIdCardNo,
            // 护照号
            SysUserInfoModel::getPassportNo,
            // 联系电话
            SysUserInfoModel::getLinkPhone,
            // 1：男 2：女 0：不详
            SysUserInfoModel::getSex,
            // 省id
            SysUserInfoModel::getProvinceId,
            // 市id
            SysUserInfoModel::getCityId,
            // 县id
            SysUserInfoModel::getCountyId,
            // 县级以上名字，中间用-分割
            SysUserInfoModel::getCountyName,
            // 详细地址
            SysUserInfoModel::getAddress,
            // qq号
            SysUserInfoModel::getQqNo,
            // 微信号
            SysUserInfoModel::getWeixiNo,
            // 头像
            SysUserInfoModel::getAvatar,
            // 备注
            SysUserInfoModel::getRemark
        );
    }


}
